home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / crwdemo / outputde.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-05  |  14.1 KB  |  422 lines

  1. VERSION 2.00
  2. Begin Form Outputdest 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Output Destination"
  5.    ClientHeight    =   4665
  6.    ClientLeft      =   1905
  7.    ClientTop       =   1560
  8.    ClientWidth     =   5910
  9.    Height          =   5070
  10.    Left            =   1845
  11.    LinkTopic       =   "Form2"
  12.    ScaleHeight     =   4665
  13.    ScaleWidth      =   5910
  14.    Top             =   1215
  15.    Width           =   6030
  16.    Begin CommandButton Command2 
  17.       Caption         =   "Select Printer"
  18.       Height          =   375
  19.       Left            =   4050
  20.       TabIndex        =   15
  21.       Top             =   840
  22.       Visible         =   0   'False
  23.       Width           =   1695
  24.    End
  25.    Begin CommonDialog CMDialog1 
  26.       Copies          =   1
  27.       FromPage        =   1
  28.       Left            =   4200
  29.       Top             =   3600
  30.       ToPage          =   1
  31.    End
  32.    Begin SSCheck Check3D1 
  33.       Caption         =   "No Print Controls"
  34.       Height          =   495
  35.       Left            =   4020
  36.       TabIndex        =   14
  37.       Top             =   1410
  38.       Width           =   1695
  39.    End
  40.    Begin CommandButton Command5 
  41.       Caption         =   "Help"
  42.       Height          =   375
  43.       Left            =   2880
  44.       TabIndex        =   1
  45.       Top             =   3600
  46.       Width           =   1095
  47.    End
  48.    Begin CommandButton Command4 
  49.       Caption         =   "Cancel"
  50.       Height          =   375
  51.       Left            =   1560
  52.       TabIndex        =   12
  53.       Top             =   3600
  54.       Width           =   1095
  55.    End
  56.    Begin CommandButton Command3 
  57.       Caption         =   "OK"
  58.       Height          =   375
  59.       Left            =   120
  60.       TabIndex        =   11
  61.       Top             =   3600
  62.       Width           =   1215
  63.    End
  64.    Begin SSOption Option3D1 
  65.       Caption         =   "Export"
  66.       Height          =   495
  67.       Index           =   3
  68.       Left            =   2520
  69.       TabIndex        =   10
  70.       TabStop         =   0   'False
  71.       Top             =   2520
  72.       Width           =   1215
  73.    End
  74.    Begin SSOption Option3D1 
  75.       Caption         =   "File"
  76.       Height          =   495
  77.       Index           =   2
  78.       Left            =   480
  79.       TabIndex        =   9
  80.       TabStop         =   0   'False
  81.       Top             =   2520
  82.       Width           =   1215
  83.    End
  84.    Begin SSOption Option3D1 
  85.       Caption         =   "Printer"
  86.       Height          =   495
  87.       Index           =   1
  88.       Left            =   2520
  89.       TabIndex        =   8
  90.       TabStop         =   0   'False
  91.       Top             =   1800
  92.       Width           =   1215
  93.    End
  94.    Begin SSOption Option3D1 
  95.       Caption         =   "Window"
  96.       Height          =   495
  97.       Index           =   0
  98.       Left            =   495
  99.       TabIndex        =   7
  100.       Top             =   1800
  101.       Value           =   -1  'True
  102.       Width           =   1215
  103.    End
  104.    Begin SSFrame Frame3D2 
  105.       Height          =   1695
  106.       Left            =   240
  107.       TabIndex        =   6
  108.       Top             =   1440
  109.       Width           =   3615
  110.    End
  111.    Begin SSFrame Frame3D1 
  112.       Height          =   615
  113.       Left            =   240
  114.       TabIndex        =   5
  115.       Top             =   600
  116.       Width           =   3615
  117.       Begin Label Label1 
  118.          Alignment       =   2  'Center
  119.          BackColor       =   &H00C0C0C0&
  120.          Caption         =   "OutPut Destination"
  121.          Height          =   255
  122.          Left            =   480
  123.          TabIndex        =   2
  124.          Top             =   240
  125.          Width           =   2895
  126.       End
  127.    End
  128.    Begin CommandButton Command1 
  129.       Caption         =   "Print"
  130.       Height          =   375
  131.       Left            =   4050
  132.       TabIndex        =   4
  133.       Top             =   360
  134.       Width           =   1695
  135.    End
  136.    Begin SSPanel StatusBar 
  137.       Alignment       =   1  'Left Justify - MIDDLE
  138.       BorderWidth     =   1
  139.       Height          =   495
  140.       Left            =   0
  141.       TabIndex        =   3
  142.       Top             =   4200
  143.       Width           =   7335
  144.    End
  145.    Begin SSPanel Panel3D1 
  146.       Alignment       =   1  'Left Justify - MIDDLE
  147.       BevelInner      =   1  'Inset
  148.       BevelWidth      =   2
  149.       BorderWidth     =   1
  150.       Height          =   3015
  151.       Left            =   120
  152.       TabIndex        =   0
  153.       Top             =   360
  154.       Width           =   3855
  155.    End
  156.    Begin Label Label2 
  157.       Caption         =   "Label2"
  158.       Height          =   495
  159.       Left            =   2760
  160.       TabIndex        =   13
  161.       Top             =   2280
  162.       Width           =   1215
  163.    End
  164. Dim ExportOptions As PEExportOptions
  165. Dim ExportOptionsValid As Integer
  166. Sub Command1_Click ()
  167. Dim C As New Child
  168. 'Specify whether to turn print controls on or off
  169. If Option3d1(0) = True Then
  170.   If PEShowPrintControls(JobNum, True) = False Then
  171.       RCode = GetErrorString(JobNum)
  172.       MsgBox "PEShowPrintControls Error #: " + Str(ErrorCode) + " - " + RCode
  173.       Exit Sub
  174.   End If
  175.   If Check3d1.Value = True Then
  176.     If PEShowPrintControls(JobNum, False) = False Then
  177.       RCode = GetErrorString(JobNum)
  178.       MsgBox "PEShowPrintControls Error #: " + Str(ErrorCode) + " - " + RCode
  179.       Exit Sub
  180.     Else
  181.       Main.Command1.Visible = True
  182.       Main.Command2.Visible = True
  183.       Main.Command3.Visible = True
  184.       Main.Command4.Visible = True
  185.       Main.Command5.Visible = True
  186.       
  187.       Unload OutputDest
  188.       Report_ParentWindowHandle = C.hWnd
  189.       C.Caption = "MDIChild - " & Forms.Count
  190.      'Set the border style of the print window so that it has no border,max or min
  191.      'buttons, control box etc.
  192.      'Border_style% = 268435456
  193.      'Send the Print job to be printed to a window
  194.      If PEOutPutToWindow(JobNum, C.Caption, ScaleLeft, ScaleTop, ScaleWidth, ScaleHeight, 268435456, C.hWnd) = False Then
  195.       RCode = GetErrorString(JobNum)
  196.       MsgBox "PEOutputToWindow Error #: " + Str(ErrorCode) + " - " + RCode
  197.       Exit Sub
  198.      Else
  199.        OutputDest!StatusBar.Caption = "Output to Window was successful."
  200.      End If
  201.      If PEStartPrintJob(JobNum, True) = False Then
  202.       RCode = GetErrorString(JobNum)
  203.       Unload C
  204.       MsgBox "PEStartPrintJob Error #: " + Str(ErrorCode) + " - " + RCode
  205.       Exit Sub
  206.       
  207.      Else
  208.        OutputDest!StatusBar.Caption = "Printing to Window was successful."
  209.      End If
  210.     End If
  211.   Else
  212.   Unload OutputDest
  213.   'Dim C1 As New Child
  214.   Report_ParentWindowHandle = C.hWnd
  215.   C.Caption = "Crystal MDIChild - " & Forms.Count
  216.   'Set the border style of the print window so that it has no border,max or min
  217.   'buttons, control box etc.
  218.   'Border_style% = 268435456
  219.   'Send the Print job to be printed to a window
  220.   If PEOutPutToWindow(JobNum, C.Caption, ScaleLeft, ScaleTop, ScaleWidth, ScaleHeight, 268435456, C.hWnd) = False Then
  221.       RCode = GetErrorString(JobNum)
  222.       MsgBox "PEOutputToWindow Error #: " + Str(ErrorCode) + " - " + RCode
  223.       Exit Sub
  224.      
  225.   Else
  226.      OutputDest!StatusBar.Caption = "Output to Window was successful."
  227.   End If
  228.   If PEStartPrintJob(JobNum, True) = False Then
  229.       RCode = GetErrorString(JobNum)
  230.       Unload C
  231.       MsgBox "PEStartPrintJob Error #: " + Str(ErrorCode) + " - " + RCode
  232.       Exit Sub
  233.       
  234.   Else
  235.    OutputDest!StatusBar.Caption = "Printing to Window was successful."
  236.   End If
  237.      
  238.    Screen.MousePointer = 0
  239.   End If
  240. End If
  241.   If Option3d1(1) = True Then
  242.      'Output to printer
  243.      MsgBox "Printer"
  244.      Check3d1.Enabled = False
  245.      CMDialog1.Action = 5
  246.      
  247.      Copies = CMDialog1.Copies
  248.      'Need to trap if user hits cancel in Commondialogue somehow
  249.      If PEOutputToPrinter(JobNum, Copies) = False Then
  250.       RCode = GetErrorString(JobNum)
  251.       MsgBox "PEOutputToPrinter Error #: " + Str(ErrorCode) + " - " + RCode
  252.       Exit Sub
  253.      Else
  254.         OutputDest!StatusBar.Caption = "Output to printer Successful."
  255.      End If
  256.      If PEStartPrintJob(JobNum, True) = False Then
  257.       RCode = GetErrorString(JobNum)
  258.       MsgBox "PEStartPrintJob Error #: " + Str(ErrorCode) + " - " + RCode
  259.       Exit Sub
  260.      Else
  261.         OutputDest!StatusBar.Caption = "Printing to Printer was successful."
  262.      End If
  263.      
  264.    End If
  265.   If Option3d1(2) = True Then
  266.      MsgBox "Note: File format will be Character Seperated with a string delimiter of a single quote and a field delimiter of a comma. To output to any other file formats please refer to the documentation and modify the code manually. Otherwise it is recommended that the Export option be used."
  267.     'Output to File
  268.     Check3d1.Enabled = False
  269.   Dim FileName As String, Msg As String
  270.   Dim choice As Integer, FileType As Integer
  271.   'Dim Options As PEPrintFileOptions
  272.   Dim Options As PECharSepFileOptions
  273.   FileName = InputBox("Please Enter Report File Name with full path:", "Report File Name")
  274.   'FileType = PE_FT_TABSEPERATED
  275.   FileType = PE_FT_CHARSEPARATED
  276.   Options.StructSize = Len(Options)  ' Initialize size of structure
  277.   Options.UseReportNumberFmt = False
  278.   Options.UseReportDateFormat = True
  279.   Options.StringDelimiter = "'"
  280.   Options.FieldDelimiter = "," + Chr$(0)
  281.   ' We can't output to the file, unless it does not exist. Therefore
  282.   ' Check for the existence of the file.  If it does exist check with
  283.   ' the user to see if we can erase it.
  284.   If exists(FileName) Then
  285.     Msg = FileName + " already exits.  OK to overwrite?"
  286.     choice = MsgBox(Msg, 36)
  287.     If choice = 6 Then  ' The user said yes
  288.       Kill FileName
  289.       If PEOutputToFile(JobNum, FileName, FileType, Options) = False Then
  290.         ' Handle error
  291.       RCode = GetErrorString(JobNum)
  292.       MsgBox "PEOutputToFile Error #: " + Str(ErrorCode) + " - " + RCode
  293.       Exit Sub
  294.       Else
  295.         OutputDest!StatusBar.Caption = "Output to file Successful."
  296.         If PEStartPrintJob(JobNum, True) = False Then
  297.           RCode = GetErrorString(JobNum)
  298.           MsgBox "PEStartPrintJob Error #: " + Str(ErrorCode) + " - " + RCode
  299.           Exit Sub
  300.         Else
  301.           OutputDest!StatusBar.Caption = "Printing to File was successful."
  302.         End If
  303.       End If
  304.     End If
  305.   Else
  306.     If PEOutputToFile(JobNum, FileName, FileType, Options) = False Then
  307.       ' Handle error
  308.       RCode = GetErrorString(JobNum)
  309.       MsgBox "PEOutputToFile Error #: " + Str(ErrorCode) + " - " + RCode
  310.       Exit Sub
  311.     Else
  312.         OutputDest!StatusBar.Caption = "Output to file Successful."
  313.        
  314.     End If
  315.   End If
  316.   End If
  317.   If Option3d1(3) = True Then
  318.     If JobNum = 0 Then
  319.         MsgBox "Job not open"
  320.         Exit Sub
  321.     End If
  322.     If ExportOptionsValid = 0 Then
  323.         Call InitExportOptions
  324.     End If
  325.     ' PEGetExportOptions gets complete information about format and
  326.     ' destination for the export
  327.     ' The ExportOptions must be passed to PEExportTo before calling PEStartPrintJob
  328.     ExportOptionsValid = PEGetExportOptions(JobNum, ExportOptions)
  329.      
  330.     If ExportOptionsValid = 0 Then
  331.         Call InitExportOptions
  332.     End If
  333.     ' Whenever you call PEExportTo, you must ensure that the format
  334.     ' and dll names have been filled in
  335.     ' You can do this by assigning specific names (as InitExportOptions does)
  336.     ' or by calling PEGetExportOptions
  337.     ' If the ExportOptions structure doesn't contain all information needed
  338.     ' by a format or destination dll, it will ask for the information
  339.     ' when you call PEStartPrintJob
  340.     ' An ExportOptions structure filled in by PEGetExportOptions always has
  341.     ' all the information needed by both dll's
  342.     ExportOptionsValid = PEExportTo(JobNum, ExportOptions)
  343.     If ExportOptionsValid = 0 Then
  344.         RCode = GetErrorString(JobNum)
  345.         MsgBox "PEExportTo Error #: " + Str(ErrorCode) + " - " + RCode
  346.         MsgBox "Cannot print - no export options"
  347.         Exit Sub
  348.     End If
  349.     If PEStartPrintJob(JobNum, True) = False Then
  350.        RCode = GetErrorString(JobNum)
  351.        MsgBox "PEStartPrintJob Error #: " + Str(ErrorCode) + " - " + RCode
  352.        Exit Sub
  353.     Else
  354.        OutputDest!StatusBar.Caption = "Export was successful."
  355.     End If
  356.     Check3d1.Enabled = False
  357.   End If
  358. End Sub
  359. Sub Command3_Click ()
  360.  Unload Me
  361. End Sub
  362. Sub Command4_Click ()
  363.  Unload Me
  364. End Sub
  365. Sub Command5_Click ()
  366.  RCode = Shell("Winhelp c:\crw\crw.hlp", 3)
  367.  If RCode = False Then
  368.    MsgBox ("RedPoint cannot find the Crystal Help file in C:\CRW directory")
  369.  End If
  370. End Sub
  371. Function exists (f As String) As Integer
  372. ' What follows is code for the exists function
  373. ' This function returns True if a given file exists, False otherwise
  374.   Dim n As Integer
  375.   On Error GoTo handler
  376.   n = FreeFile
  377.   ' Try to open file for input.  If successful, file exists
  378.   Open f For Input As #n
  379.   Close #n
  380.   exists = True
  381.   Exit Function
  382. handler:
  383.   ' If we get here the file does not exist
  384.   exists = False
  385.   Exit Function
  386. End Function
  387. Sub Form_Load ()
  388.  OutputDest!StatusBar.Caption = "Ready"
  389. End Sub
  390. Sub InitExportOptions ()
  391.     ExportOptions.StructSize = Len(ExportOptions)
  392.     ExportOptions.FormatDLLName = "uxftext" + Chr$(0)
  393.     ExportOptions.FormatType = 0
  394.     ExportOptions.FormatOptions = 0
  395.     ExportOptions.DestinationDLLName = "uxddisk" + Chr$(0)
  396.     ExportOptions.DestinationType = 0
  397.     ExportOptions.DestinationOptions = 0
  398.     ExportOptions.NFormatOptionsBytes = 0
  399.     ExportOptions.NDestinationOptionsBytes = 0
  400.     ExportOptionsValid = 0
  401. End Sub
  402. Sub Option3D1_Click (Index As Integer, Value As Integer)
  403.  If Option3d1(0).Value = True Then
  404.     Check3d1.Enabled = True
  405.     Command1.Caption = "Print"
  406.     Command2.Visible = False
  407.  End If
  408.  If Option3d1(1).Value = True Then
  409.    Command1.Caption = "Print"
  410.    Check3d1.Enabled = False
  411.    Command2.Visible = True
  412.  End If
  413.  If Option3d1(2).Value = True Then
  414.    Command1.Caption = "Print"
  415.    Check3d1.Enabled = False
  416.  End If
  417.  If Option3d1(3).Value = True Then
  418.    Command1.Caption = "Export"
  419.    Check3d1.Enabled = False
  420.  End If
  421. End Sub
  422.